<template>
	<view class=" jcc aic fdc ">
		<view class="my30"></view>
		<view class="my30"></view>
		<view class="loginPhone">
			<view class="w100 moauto title">
				欢迎来到云上活
			</view>
			<!-- form -->

			<view class="loginPhone-form">


				<view class="">
					<view class="aic jcb">
						<u-input v-model="phone" placeholder="输入手机号" />
						<view class="llt-main-color" @tap="getCode">
							{{tips}}
						</view>


					</view>
					<u-line color="#919599"></u-line>
				</view>
				<view class="my30"></view>
				<view class="">
					<u-input v-model="code" placeholder="输入短信验证码" />
					<u-line color="#919599"></u-line>
				</view>
				<view class="my30"></view>
				
				<view class="btn">
					<u-button type="primary" 
					 @click="phoneLogin"
					 :custom-style="customStyle">
						登录
					</u-button>
				</view>
			</view>
		</view>
		<u-verification-code startText="获取验证码"
		 :seconds="seconds" 
		 @end="end" 
		 @start="start" 
		 ref="uCode"
			@change="codeChange"></u-verification-code>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '获取验证码',
				seconds: 60,
				phone: "",
				code:""
			};
		},
		onLoad() {
			this.phone = this.$store.state.vuex_user_phone
		},
		methods: {
			phoneLogin(){
				this.$u.api.phoneLogin({
									phone: 18336465466,
									_t: 1627608595
								})
							.then(res=>{
												console.log(res);
											})
			},
			codeChange(text) {
				this.tips = text;
				
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				this.$u.toast('倒计时结束');
			},
			start() {
			 this.$u.api.demoGetCode({
			 					phone: 18336465466,
			 					_t: 1627608595
			 				})
							.then(res=>{
								console.log(res);
							})
				this.$u.toast('倒计时开始');
			}
		}
	}
</script>

<style lang="scss" scoped>
	.loginPhone {
		width: 600rpx;

		.title {
			font-size: 50rpx;
		}
	}

	.loginPhone-form {
		margin-top: 80rpx;
		.btn{
			margin-top: 80rpx;
		}
	}
</style>
